import axios from '@/api'
import MD5 from 'js-md5'
import { IArea } from './area'
import { IPlant, IYKTAccount } from './famer'

export interface ICountCrop {
  request: {
    is_used: string;
  }
  response: {
    s_a_id: string;
    s_a_nam: string;
    s_a_nam_all: string;
    member_num: string;
    is_used: string;
    plant_size: string;
    bt_size: string;
    pay_price: string;
  }
}

export interface ICropMember {
  request: {
    is_used: string;
  }
  response: {
    s_a_id: string;
    s_a_nam: string;
    s_a_nam_all: string;
    member_id: string;
    member_law_id: string;
    member_nam: string;
    member_tel: string;
    member_bank_num: string;
    member_bank_code: string;
    readme: string;
    member_addr: string;
    plant_size: string;
    bt_size: string;
  }
}


class CropMemberServices {
  constructor() { }

  /**
   * 获取一次性补贴统计信息列表
   *
   * @param {IGetAdminList['request']} data
   * @returns
   * @memberof UserServices
   */
  getCountList(data: ICountCrop['request']) {
    return axios.post<unknown, Api.ResponseOptions<ICountCrop['response']>>('/btbusiness/crop-member/get-count', data)
  }

  /**
   * 删除辖区未补贴用户
   *
   * @param {{ s_a_id: string }} data
   * @returns
   * @memberof CropMemberServices
   */
  delNextUnUsedMember(data: { s_a_id: string }) {
    return axios.post<unknown, Api.ResponseOptions>('/btbusiness/crop-member/del-area-member', data)
  }
  
  /**
   * 获取一次性补贴详细列表
   *
   * @param {{ s_a_id: string }} data
   * @returns
   * @memberof CropMemberServices
   */
  getList(data: { s_a_id: string }) {
    return axios.post<unknown, Api.ResponseOptions>('/btbusiness/crop-member/get-list', data)
  }

  /**
   * 同步本年农户和大户数据
   *
   * @param {{ s_a_id: string }} data
   * @returns
   * @memberof CropMemberServices
   */
  syncThisYearData(data: { s_a_id: string, target?: string }) {
    return axios.post<unknown, Api.ResponseOptions>('/btbusiness/crop-member/import-data', data)
  }

  /**
   * 同步年首次一次补导入基础数据
   *
   * @param {{ s_a_id: string }} data
   * @returns
   * @memberof CropMemberServices
   */
   syncThisYearFirstData(data: { s_a_id: string, target?: string }) {
    return axios.post<unknown, Api.ResponseOptions>('/btbusiness/crop-member/import-first', data)
  }

  /**
   * 同步其他项目和年份的数据
   *
   * @param {{ s_a_id: string }} data
   * @returns
   * @memberof CropMemberServices
   */
  syncData(data: { s_a_id: string, target_task_id: string, target_year: string }) {
    return axios.post<unknown, Api.ResponseOptions>('/btbusiness/crop-member/sync-data', data)
  }

  /**
   * 编辑用户
   *
   * @param {Partial<ICropMember['response']>} data
   * @returns
   * @memberof CropMemberServices
   */
  updateCropMember(data: Partial<ICropMember['response']>) {
    return axios.post<unknown, Api.ResponseOptions>('/btbusiness/crop-member/edit-member', data)
  }

  /**
   * 删除用户
   *
   * @param {{ member_id: string }} data
   * @returns
   * @memberof CropMemberServices
   */
  deleteCropMember(data: { member_id: string }) {
    return axios.post<unknown, Api.ResponseOptions>('/btbusiness/crop-member/del-member', data)
  }

  /**
   * 获取种粮信息
   *
   * @param {(Partial<Pick<IPlant, 's_a_id'>> & { member_id: string })} data
   * @returns
   * @memberof CropMemberServices
   */
  getCropMemberPlants(data: Partial<Pick<IPlant, 's_a_id'>> & { member_id: string }) {
    return axios.post<unknown, Api.ResponseOptions>('/btbusiness/crop-member/get-plant', data)
  }
  
  /**
   * 更新种粮信息
   *
   * @param {Partial<IPlant>} data
   * @returns
   * @memberof CropMemberServices
   */
  updateCropMemberPlant(data: Partial<IPlant>) {
    return axios.post<unknown, Api.ResponseOptions>('/btbusiness/crop-member/edit-plant', data)
  }

  /**
   * 导出统计数据
   *
   * @param {{
   *     s_a_id: string;
   *     keys: string[]
   *   }} data
   * @returns
   * @memberof CropMemberServices
   */
  exportCropMemberCount(data: {
    s_a_id: string;
    keys: string[]
  }) {
    return axios.post<unknown, Api.ResponseOptions>('/btbusiness/crop-member/export-member-count', data, { responseType: 'blob', customHandler: true })
  }

  /**
   * 导出统计数据
   *
   * @param {{
   *     s_a_id: string;
   *     keys: string[]
   *   }} data
   * @returns
   * @memberof CropMemberServices
   */
  exportCropMemberList(data: {
    s_a_id: string;
    keys: string[]
  }) {
    return axios.post<unknown, Api.ResponseOptions>('/btbusiness/crop-member/export-member-list', data, { responseType: 'blob', customHandler: true })
  }

  /**
   * 导入execl数据
   *
   * @template T
   * @param {T[]} data
   * @returns
   * @memberof CropMemberServices
   */
  importCropMemberList<T = unknown>(data: { data: T[], file_nam: string, s_a_id: string, type: number }) {
    return axios.post<Api.ResponseOptions<unknown, {msg: string[]}>>('/btbusiness/crop-member/batch-insert-member', data, { customHandler: true })
  }

  /**
   * 更新补贴状态
   *
   * @param {{
   *     member_id: string;
   *     is_area: string;
   *     is_used: string;
   *   }} data
   * @returns
   * @memberof CropMemberServices
   */
  setCropMemberUsed(data: {
    member_id?: string;
    is_area?: string;
    is_used: string;
  }) {
    return axios.post<unknown, Api.ResponseOptions>('/btbusiness/crop-member/set-used', data)
  }

  /**
   * 批量修改字段
   *
   * @param {{
   *     s_a_id: string;
   *     type: string;
   *     value: string
   *   }} data
   * @returns
   * @memberof CropMemberServices
   */
  batchModifyField(data: {
    s_a_id: string;
    type: string;
    value: string
  }) {
    return axios.post<Api.ResponseOptions<unknown, {msg: string[]}>>('/btbusiness/crop-member/clean-size', data)
  }

  /**
   * 导入一卡通银行卡信息
   *
   * @param {{ s_a_id: string, file_nam?: string; data: IYKTAccount[] }} data
   * @returns
   * @memberof CropMemberServices
   */
   ImportYKTAccount(data: { s_a_id: string, file_nam?: string; data: IYKTAccount[] }) {
    return axios.post<Api.ResponseOptions<string[], { msg: string[] }>>(
      '/btbusiness/crop-member/import-account',
      data,
      { customHandler: true }
    )
  }
}

export const cropMemberServices = new CropMemberServices()

export default CropMemberServices